//
//  DataManage.m
//  Borderless
//
//  Created by Bager on 2017/10/11.
//  Copyright © 2017年 Bager. All rights reserved.
//

#import "DataManage.h"

@implementation DataManage

#pragma mark [存入]

//存入字符串类型数据
+ (void)saveInfoWithKey:(NSString *)key andValue:(NSString *)value{
    if ([value isNullString]) {
        value = @"";
    }
    [[NSUserDefaults standardUserDefaults]setObject:value forKey:key];
    //同步存储到磁盘中
    [[NSUserDefaults standardUserDefaults]synchronize];
}

//存入布朗型数据
+ (void)saveBoolWithKey:(NSString *)key andValue:(BOOL)value{
    [self saveInfoWithKey:key andValue:value == YES?@"YES":@"NO"];
}

//存入对象
+ (void)saveObjWithKey:(NSString *)key andValue:(NSObject *)value{
    NSData *data = [NSKeyedArchiver archivedDataWithRootObject:[value copy]];
    [[NSUserDefaults standardUserDefaults] setObject:data forKey:key];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

#pragma mark [取出]

//取出字符串类型数据
+ (NSString *)getInfoWithKey:(NSString *)key{
    return [[NSUserDefaults standardUserDefaults]objectForKey:key];
}

//取出布朗型数据
+ (BOOL)getBoolWithKey:(NSString *)key{
    return [[self getInfoWithKey:key] isEqualToString:@"YES"];
}

//取出对象
+ (id)getObjWithKey:(NSString *)key{
    NSData *data = [[NSUserDefaults standardUserDefaults] objectForKey:key];
    return [NSKeyedUnarchiver unarchiveObjectWithData:data];
}

@end
